package hu.mapro.flang.gwt.client.ui;

import hu.mapro.flang.gwt.client.request.ApplicationRequestFactory;
import hu.mapro.gwtui.client.Menu;
import hu.mapro.gwtui.client.MenuGroup;
import hu.mapro.gwtui.client.VisibilityUtils;
import hu.mapro.gwtui.client.login.LoginService;
import hu.mapro.gwtui.client.login.LoginUtils;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.SimpleEventBus;

@Singleton
public class UiBuilder {

	Menu menu;
	private LoginService loginService; 
	private ApplicationRequestFactory requestFactory;

	@Inject
	public UiBuilder(Menu menu, LoginService loginService,
			ApplicationRequestFactory requestFactory) {
		super();
		this.menu = menu;
		this.loginService = loginService;
		this.requestFactory = requestFactory;
	}

	private MenuGroup practiceMenuGroup;
	private MenuGroup manageMenuGroup;

	public MenuGroup getPracticeMenuGroup() {
		return practiceMenuGroup;
	}

	public MenuGroup getManageMenuGroup() {
		return manageMenuGroup;
	}
	
	public void build() {
		requestFactory.initialize(new SimpleEventBus());
		
		practiceMenuGroup = menu.addMenuGroup();
		practiceMenuGroup.setText("Practice");
		VisibilityUtils.addVisibility(LoginUtils.whenLoggedIn(loginService), practiceMenuGroup);
		
		manageMenuGroup = menu.addMenuGroup();
		manageMenuGroup.setText("Manage");
		VisibilityUtils.addVisibility(LoginUtils.whenLoggedIn(loginService), manageMenuGroup);
		
		//new BookUiBuilder(this).build();
		
	}
	
	public ApplicationRequestFactory getRequestFactory() {
		return requestFactory;
	}

}
